package source.table;

import source.kernel.DB;
import source.kernel.base.Table;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * @author Hai Thomson
 */
public class hosts extends Table {
	public hosts() {
		super("hosts", "hostid");
	}

	public Map fetchNextHost(String hostid) throws SQLException {
		String sql = "SELECT * FROM hosts,interface WHERE hosts.hostid = interface.hostid AND hosts.hostid > ? AND hosts.available = 1 LIMIT 1";
		return DB.queryFirstRow(sql, hostid);
	}

	public List fetchHostTemplate(String hostid) throws SQLException {
		String sql = "SELECT hosts.host FROM hosts,hosts_templates WHERE hosts_templates.hostid = ? AND hosts_templates.templateid = hosts.hostid";
		return DB.queryFirstColumn(sql, hostid);
	}
}
